<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .outer{
            width:300px;
            height: 300px;
            background-color: red;
        }
        .box{
            width: 200px;
            height: 200px;
            background-color: purple;
        }
        .inner{
            width: 100px;
            height: 100px;
            background-color: green;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="box">
            <div class="inner">

            </div>
        </div>
    </div>
    <script>
        let outer = document.querySelector('.outer')
        let box = document.querySelector('.box')
        let inner = document.querySelector('.inner')

        // 阻止事件传播也很简单，直接event.stopPropagation()即可
        inner.onclick = (e)=>{
            e.stopPropagation()
            console.log('inner');
        }

        box.onclick = (e)=>{
            e.stopPropagation()
            console.log('box');
        }

        outer.onclick = (e)=>{
            e.stopPropagation()
            console.log('outer');
        }
    </script>
</body>
</html>